package com.ruoyi.web.controller.system;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.SysKey;
import com.ruoyi.system.service.SysKeyService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/key")
public class SysKeyController extends BaseController {

    @Resource
    private SysKeyService sysKeyService;

    /**
     * @Deprecated 查询自己的卡密
     */
    @GetMapping(value = "/getMyKeyTableDataInfo")
    private TableDataInfo getMyKeyTableDataInfo(SysKey sysKey) {
        startPage();
        List<SysKey> list = sysKeyService.getMyKeyTableDataInfo(sysKey);
        return getDataTable(list);
    }

    /**
     * @Deprecated 新增自己的卡密
     */
    @PostMapping(value = "/addKey")
    private AjaxResult addKey(@RequestBody SysKey sysKey) {
        return sysKeyService.addKey(sysKey);
    }


    /**
     * @Deprecated 删除自己的卡密
     */
    @PostMapping(value = "/delKey")
    private AjaxResult delKey(@RequestBody SysKey sysKey) {
        return sysKeyService.delKey(sysKey);
    }

    /**
     * @Deprecated 设置单个用户到期
     */
    @PostMapping(value = "/gq")
    private AjaxResult gq(@RequestBody SysKey sysKey) {
        return sysKeyService.gq(sysKey);
    }

    /**
     * @Deprecated 设置批量用户到期
     */
    @PostMapping(value = "/pldq")
    private AjaxResult pldq(@RequestBody String keyList) {
        JSONObject jsonObject = JSONObject.parseObject(keyList);
        String data = jsonObject.getString("keyList");

        return sysKeyService.plda(data);
    }

    /**
     * @Deprecated 删除自己的多个卡密
     */
    @DeleteMapping("/{ids}")
    private AjaxResult delKeyList(@PathVariable Long[] ids) {
        return sysKeyService.delKeyList(ids);
    }

    /**
     * @Deprecated 封停卡密
     */
    @PostMapping("/shutDown")
    private AjaxResult shutDown(String key) {
        return sysKeyService.shutDown(key);
    }
}
